"""
用户数据模式
"""

from typing import Optional
from datetime import datetime
from pydantic import BaseModel, EmailStr


class UserBase(BaseModel):
    """用户基础模式"""
    username: str
    email: EmailStr
    nickname: Optional[str] = None
    avatar: Optional[str] = None


class UserCreate(UserBase):
    """创建用户模式"""
    password: str


class UserUpdate(BaseModel):
    """更新用户模式"""
    username: Optional[str] = None
    email: Optional[EmailStr] = None
    nickname: Optional[str] = None
    avatar: Optional[str] = None
    password: Optional[str] = None


class UserResponse(UserBase):
    """用户响应模式"""
    id: int
    is_active: bool
    is_admin: bool
    created_at: datetime
    updated_at: datetime
    last_login: Optional[datetime] = None
    
    class Config:
        from_attributes = True


class UserLogin(BaseModel):
    """用户登录模式"""
    username: str
    password: str


class UserToken(BaseModel):
    """用户令牌模式"""
    access_token: str
    token_type: str
    expires_in: int


class UserLoginRequest(BaseModel):
    """用户登录请求模式"""
    username: str
    password: str


class UserRegisterRequest(BaseModel):
    """用户注册请求模式"""
    username: str
    email: str
    password: str
    confirm_password: str
    nickname: Optional[str] = None